package ModelLayer;
import java.util.ArrayList;

/**
 * Vestbjerg project
 * @GroupB2 (UCN - Computer Science DMAJ0914) 
 */
public class Machinery extends Item
{
    // instance variables
    private ArrayList<Unit> unitList;

    /**
     * Constructor for objects of class Machinery
     */
    public Machinery(String barcode, String name, String description, double price)
    {
        super(barcode, name, description, price);
        unitList = new ArrayList<Unit>();
    }

    public ArrayList<Unit> getUnitList() 
    {
        return unitList;
    }

    public void addUnit(Unit unit) 
    {
        if(!unitList.contains(unit)) {
            unitList.add(unit);
        }
    }

    public Unit findUnit(String serialNumber) 
    {
        Unit returnUnit = null;
        for(Unit unit : unitList) 
        {
            if(unit.getSerialNumber().equals(serialNumber)) 
            {
                returnUnit = unit;
            }
        }
        return returnUnit;
    }

    public void deleteUnit(Unit unit) 
    {
        if(unitList.contains(unit)) 
        {
            unitList.remove(unit);
        }
    }
}
